package com.yljk.yljkproject.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.yljk.yljkproject.R;


/**
 * 提示共用Dialog
 */
public class AlertDialog extends Dialog implements OnClickListener {

    private Context mContext;

    private String mTitle, mMessage, mPositive, mNegative;

    private TextView mTitleTextView, mMessageTextView, mPositiveButton, mNegativeButton;

    private TextView context_tv;

    private OnDialogListener mOnDialogListener;

    private OnOneButtonDialogListener mOneButtonListener;

    private View mProgressLayout;

    public AlertDialog(Context context) {
        super(context, R.style.dialog);
    }

    public AlertDialog(Context context, int dialogMode) {
        super(context, R.style.dialog);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_alert);
        findView();
        setListener();
        initView();
    }

    private void findView() {
        mTitleTextView = (TextView) findViewById(R.id.dialog_title);
        mMessageTextView = (TextView) findViewById(R.id.dialog_content);
        mPositiveButton = (TextView) findViewById(R.id.positive_button);
        mNegativeButton = (TextView) findViewById(R.id.negative_button);
        mProgressLayout = findViewById(R.id.progress_layout);
        context_tv = (TextView) findViewById(R.id.context_tv);
    }

    private void setListener() {
        mPositiveButton.setOnClickListener(this);
        mNegativeButton.setOnClickListener(this);
    }

    private void initView() {
        View twoButton = findViewById(R.id.two_button);
        mMessageTextView.setText(mMessage);
        //两个btn
        mMessageTextView.setVisibility(View.VISIBLE);
        mProgressLayout.setVisibility(View.GONE);
        twoButton.setVisibility(View.VISIBLE);
        mNegativeButton.setText(mNegative);
        context_tv.setText(mMessage);
    }

    public void setTitleText(String title) {
        mTitle = title;
    }

    public void setMessageText(String msg) {
        mMessage = msg;
    }

    public void setPositiveText(String text) {
        mPositive = text;
    }

    public void setNegativeText(String text) {
        mNegative = text;
    }

    public interface OnDateTimeSetListener {
        void onDateTimeSet(int year, int monthOfYear, int dayOfMonth);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.positive_button:
                if (mOnDialogListener.onPositiveButton()) {
                    dismiss();
                }
                break;
            case R.id.negative_button:
                mOnDialogListener.onNegativeButton();
                dismiss();
                break;
            default:
                break;
        }
    }

    public interface OnDialogListener {
        boolean onPositiveButton();

        void onNegativeButton();
    }

    public interface OnOneButtonDialogListener {
        void onPositiveButton();
    }

    public void setOnDialogListener(OnDialogListener listener) {
        mOnDialogListener = listener;
    }

    public void setOnOneButtonDialogListener(OnOneButtonDialogListener listener) {
        mOneButtonListener = listener;
    }

}

